﻿// JSON
// 一个无序的键值对集合。
// 使用花括号{}包围
// 每个键值对由一个键和一个值组成，键和值之间用:分隔，键值对之间用,分隔。
// 键必须是字符串，并且用双引号""包围
// 值可以是字符串，数值，布尔值，数组，对象或null

using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System.Formats.Asn1;
using System.Runtime.InteropServices;

JObject obj = new JObject();
obj["test"] = 1;
obj.Add("id",false);
var str = obj.ToString();

JArray arr = new JArray();
arr.Add(obj);
arr.Add(obj);
arr.Add(obj);
arr.Add(obj);
arr.Add(obj);
arr.Add(obj);

str = arr.ToString();

JObject obj2 = new JObject();
obj2["DialogData"] = arr;

str = obj2.ToString();

using (StreamReader sr = new StreamReader("../../../Json.json"))
{
    str = sr.ReadToEnd();
}

JObject obj3 = JObject.Parse(str);

List<DialogData> list = new List<DialogData>();

var temp = obj3["DialogData"];
if (temp != null)
{
    foreach (var item in temp)
    {
        DialogData data = JsonConvert.DeserializeObject<DialogData>(item.ToString());
        list.Add(data);
    }
}

DialogData d = new DialogData();
d.id = 123;
d.isOption = true;
d.content1 = "hello";
d.nextId1 = 321;
d.content2 = "nihao";
d.nextId2 = 10;

// 存档
str = JsonConvert.SerializeObject(d,Formatting.Indented);

using (StreamWriter sw = new StreamWriter("../../../data.json"))
{
    sw.WriteLine(str);
}

// 读档
using (StreamReader sr = new StreamReader("../../../data.json"))
{
    str = sr.ReadToEnd();
}
DialogData newdata = JsonConvert.DeserializeObject<DialogData>(str);

[DllImport("winmm.dll")]
static extern void mciSenString(string command, string? ret = null, uint retLen = 0, uint callback = 0);

// 打开音乐
mciSenString("open ../../../成功时刻.wav alias music");
// 播放音乐
mciSenString("play music");

// 调整音量
//string temp1 = "               ";
//mciSenString("status music volume", temp1, 10, 0);
//Console.WriteLine(temp1);
//mciSenString("setaudio music volume to 100");

// 调整位置
mciSenString("seek music to 2000");

// 暂停音乐
Console.ReadKey();
mciSenString("pause music");
// 继续音乐
Console.ReadKey();
mciSenString("resume music");
// 暂停音乐
Console.ReadKey();
mciSenString("stop music");
// 关闭音乐
Console.ReadKey();
mciSenString("close music");
return;

struct DialogData
{
    public int id;
    public bool isOption;
    public string content1;
    public int nextId1;
    public string content2;
    public int nextId2;
}